<?php

namespace app\admin\model\chase;

use think\Model;
use traits\model\SoftDelete;

class RealOrderService extends Model
{
    use SoftDelete;


    // 表名
    protected $table = 'real_order_service';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public static function add($order_id, $params)
    {
        $data = [];
        foreach ($params as $val) {
            $data[] = [
                'order_id' => $order_id,
//                'category_id' => $val['category_id'],
                'service_id' => $val['service_id'],
                'design_id' => $val['design_id'],
                'service_name' => $val['service_name'],
                'num' => $val['num'],
                'price' => $val['price'],
                'total_money' => $val['total']
            ];
        }
        return self::insertAll($data);
    }


    public static function del($order_id)
    {
        return self::where('order_id', $order_id)->delete();
    }

    public function category()
    {
        return $this->hasOne(DesignCategory::class, 'id', 'category_id');
    }

    public function design()
    {
        return $this->hasOne(Design::class, 'id', 'design_id');
    }
}
